package com.winning.pmph.ctrl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.google.common.collect.Lists;
import com.winning.pmph.entity.*;
import com.winning.pmph.enumeration.KnowledgeSystem;
import com.winning.pmph.service.*;
import com.winning.pmph.utils.*;
import com.winning.pmph.vo.NameSuggestion;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.poi.ss.usermodel.CellType;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.jetbrains.annotations.NotNull;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Nonnull;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Function;
import java.util.stream.Collectors;

/**
 * @author wu_di@winning.com.cn
 */
@Api(value = "任务管理")
@Slf4j
@RestController
@RequestMapping("/pmph/action/task")
public class TaskCtrl {
    public static final int MAX_ROW_NUM = 1000;
    public static final String CALCULATOR_LIB_ID = "calculator_lib_id";
    public static final String FLOW_CHART_LIB_ID = "flow_chart_lib_id";
    @Resource
    private UserService userService;
    @Resource
    private KnowledgeLibService knowledgeLibService;
    @Resource
    private TaskService taskService;
    @Resource
    private TaskFileService taskFileService;
    @Resource
    private TaskItemService taskItemService;
    @Resource
    private TempKnowledgeFieldService tempKnowledgeFieldService;
    @Resource
    private ReleasedKnowledgeFieldService releasedKnowledgeFieldService;

    /**
     * 获取当前用户, 正在进行的, 某个知识体系下的所有编辑任务
     */
    @ApiOperation(value = "selectTaskList", notes = "获取当前用户, 正在进行的, 某个知识体系下的所有编辑任务")
    @GetMapping("selectTaskList")
    public Map<String, Object> selectTaskList(String systemType) {
        String username = PMPHAppUtil.getCurrentUserEnName();
        // 获取任务id, 根据子任务更新时间排序;
        List<String> taskIdList = taskItemService.list(
                new QueryWrapper<TaskItem>().lambda()
                        .select(TaskItem::getTaskId)
                        .eq(TaskItem::getEditor, username)
                        .orderByDesc(TaskItem::getUpdatedTime).orderByAsc(TaskItem::getId))
                .stream().map(TaskItem::getTaskId).distinct().collect(Collectors.toList());
        if (CollectionUtils.isEmpty(taskIdList)) {
            return null;
        }
        // 获取当前用户下已启动的任务;
        Map<String, Task> taskMap = taskService.lambdaQuery()
                .eq(StringUtils.isNotEmpty(systemType), Task::getSystemType, systemType)
                .eq(Task::getStatus, Task.STATUS_STARTED)
                .eq(Task::getDeleted, Task.NOT_DELETED)
                .in(Task::getId, taskIdList).list().stream().collect(Collectors.toMap(Task::getId, Function.identity()));
        List<Task> result = taskIdList.stream()
                .map(taskMap::get)
                .filter(Objects::nonNull)
                .collect(Collectors.toList());
        //获取当前用户下已完成的任务
        Map<String, Task> taskCompleteMap = taskService.lambdaQuery()
                .eq(StringUtils.isNotEmpty(systemType), Task::getSystemType, systemType)
                .eq(Task::getStatus, Task.STATUS_FINISHED)
                .eq(Task::getDeleted, Task.NOT_DELETED)
                .in(Task::getId, taskIdList).list().stream().collect(Collectors.toMap(Task::getId, Function.identity()));
        List<Task> completeResult = taskIdList.stream()
                .map(taskCompleteMap::get)
                .filter(Objects::nonNull)
                .collect(Collectors.toList());

        if (CollectionUtils.isNotEmpty(result)) {
            List<String> taskIds = result.stream().map(Task::getId).collect(Collectors.toList());
            List<TaskItem> list = taskItemService.lambdaQuery().in(TaskItem::getTaskId, taskIds)
                    .eq(TaskItem::getDeleted, TaskItem.NO_DELETED)
                    .and(t -> t.eq(TaskItem::getStatus, TaskItem.TYPE_TASK_EDITOR_CREATE).or().eq(TaskItem::getStatus, TaskItem.STATUS_REJECT))
                    .eq(TaskItem::getEditor, PMPHAppUtil.getCurrentUserEnName()).list();
            result.forEach(task -> {
                List<TaskItem> collect = list.stream().filter(taskItem -> task.getId().equals(taskItem.getTaskId())).collect(Collectors.toList());
                task.setTaskItemList(collect);
            });
        }
        Map<String, Object> map = new HashMap<>();
        map.put("result", result);
        map.put("completeResult", completeResult);
        return map;
    }

    /**
     * 获取任务列表
     *
     * @throws IOException 如果I/O操作异常
     */
    @ApiOperation(value = "selectTaskPage", notes = "获取任务列表接口")
    @PostMapping("selectTaskPage")
    public Page<Task> selectTaskPage(@RequestBody Task taskParam) {
        Page<Task> page = new Page<>(taskParam.getCurrentPage(), taskParam.getPageSize());
        LambdaQueryWrapper<Task> queryWrapper = Wrappers.lambdaQuery(Task.class)
                .eq(Task::getDeleted, Task.NOT_DELETED)
                .like(StringUtils.isNotBlank(taskParam.getName()), Task::getName, taskParam.getName())
                .eq(StringUtils.isNotBlank(taskParam.getCreatedBy()), Task::getCreatedBy, taskParam.getCreatedBy())
                .eq(StringUtils.isNotBlank(taskParam.getKnowledgeLibId()), Task::getKnowledgeLibId, taskParam.getKnowledgeLibId())
                .eq(Task.STATUS_ALL != taskParam.getStatus(), Task::getStatus, taskParam.getStatus())
                .eq(!Task.SYSTEM_TYPE_ALL.equals(taskParam.getSystemType()), Task::getSystemType, taskParam.getSystemType())
                .ge(Task::getEditPercent, taskParam.getEditPercentRange().get(0))
                .le(Task::getEditPercent, taskParam.getEditPercentRange().get(1))
                .ge(Task::getAuditPercent, taskParam.getAuditPercentRange().get(0))
                .le(Task::getAuditPercent, taskParam.getAuditPercentRange().get(1));
        if (CollectionUtils.isNotEmpty(taskParam.getDateRange())) {
            queryWrapper.ge(Task::getStartDate, taskParam.getDateRange().get(0));
            queryWrapper.le(Task::getEndDate, taskParam.getDateRange().get(1));
        }
        queryWrapper.orderByDesc(Task::getCreatedTime, Task::getId);
        taskService.page(page, queryWrapper);
        // 设置催办任务数;
        if (Objects.equals(taskParam.getCreatedBy(), PMPHAppUtil.getCurrentUserEnName())) {
            for (Task task : page.getRecords()) {
                switch (task.getStatus()) {
                    case Task.STATUS_NOT_STARTED: {
                        task.setEditPercent(0);
                        task.setEditPercent(0);
                        task.setNameSuggestionCount(0);
                        break;
                    }
                    case Task.STATUS_STARTED: {
                        List<TaskItem> taskItemList = taskItemService.lambdaQuery()
                                .eq(TaskItem::getTaskId, task.getId())
                                .eq(TaskItem::getDeleted, Task.NOT_DELETED).list();
                        if (CollectionUtils.isEmpty(taskItemList)) {
                            task.setEditPercent(0);
                            task.setEditPercent(0);
                            task.setNameSuggestionCount(0);
                            break;
                        }
                        // 计算 编辑完成, 审核完成的比例;
                        int editingTaskItemCount = (int) taskItemList.stream().filter(item -> item.getStatus() == TaskItem.STATUS_NOT_COMMIT || item.getStatus() == TaskItem.STATUS_REJECT).count();
                        int auditTaskItemCount = (int) taskItemList.stream().filter(item -> item.getStatus() == TaskItem.STATUS_PASS || item.getStatus() == TaskItem.STATUS_RELEASED).count();
                        int editPercent = (taskItemList.size() - editingTaskItemCount) * 100 / taskItemList.size();
                        int auditPercent = auditTaskItemCount * 100 / taskItemList.size();
                        if (editPercent != task.getEditPercent() || auditPercent != task.getAuditPercent()) {
                            task.setEditPercent(editPercent);
                            task.setAuditPercent(auditPercent);
                            taskService.updateById(task);
                        }
                        // 计算有nameSuggestion 子任务数;
                        int nameSuggestionCount = (int) taskItemList.stream().map(TaskItem::getNameSuggestion)
                                .filter(NameSuggestion::hasUnconfirmedNameSuggestion).count();
                        task.setNameSuggestionCount(nameSuggestionCount);
                        break;
                    }
                    case Task.STATUS_FINISHED: {
                        task.setEditPercent(100);
                        task.setEditPercent(100);
                        task.setNameSuggestionCount(0);
                        break;
                    }
                }
            }
        }
        return page;
    }

    @ApiOperation(value = "selectTableData", notes = "获取子任务列表接口")
    @GetMapping("selectTableData")
    public Map<String, Object> selectTableData(String taskId, String status, String name, String systemType, String taskType, String drugInfoLibCompany, Integer currentPage, Integer pageSize) {
        String userEnName = PMPHAppUtil.getCurrentUserEnName();
        List<TaskItem> items = taskService.queryTaskItem(currentPage, pageSize, taskId, status, name, systemType, userEnName, taskType, drugInfoLibCompany);
        queryDrug(items);
        int total = taskService.queryTaskItemNum(taskId, status, name, systemType, userEnName, taskType, drugInfoLibCompany);
        Map<String, Object> map = new HashMap<>(16);
        map.put("tableData", items);
        map.put("totalNum", total);
        return map;
    }

    private void queryDrug(List<TaskItem> items) {
        List<String> knowledgeIdList = items.stream().map(TaskItem::getKnowledgeId).collect(Collectors.toList());
        // 未发布知识和已发布知识knowledgeId可能相同
        List<KnowledgeField> tempFieldList = Lists.newArrayList();
        List<KnowledgeField> releaseFieldList = Lists.newArrayList();

        if (CollectionUtils.isNotEmpty(knowledgeIdList)) {
            tempKnowledgeFieldService.lambdaQuery().in(TempKnowledgeField::getKnowledgeId, knowledgeIdList)
                    .in(TempKnowledgeField::getKnowledgeLibFieldId, Const.DRUG_INFO_LIB_COMPANY_ID,
                            Const.DRUG_INFO_LIB_SOURCE_ID).list().forEach(tempFieldList::add);

            releasedKnowledgeFieldService.lambdaQuery().in(ReleasedKnowledgeField::getKnowledgeId, knowledgeIdList)
                    .in(ReleasedKnowledgeField::getKnowledgeLibFieldId, Const.DRUG_INFO_LIB_COMPANY_ID,
                            Const.DRUG_INFO_LIB_SOURCE_ID).list().forEach(releaseFieldList::add);
        }

        Map<String, String> tempCompanyMap = tempFieldList.stream().filter(item -> Const.DRUG_INFO_LIB_COMPANY_ID.equals(item.getKnowledgeLibFieldId()))
                .collect(Collectors.toMap(KnowledgeField::getKnowledgeId, KnowledgeField::getProperty));

        Map<String, String> tempSourceMap = tempFieldList.stream().filter(item -> Const.DRUG_INFO_LIB_SOURCE_ID.equals(item.getKnowledgeLibFieldId()))
                .collect(Collectors.toMap(KnowledgeField::getKnowledgeId, KnowledgeField::getProperty));

        Map<String, String> releaseCompanyMap = releaseFieldList.stream().filter(item -> Const.DRUG_INFO_LIB_COMPANY_ID.equals(item.getKnowledgeLibFieldId()))
                .collect(Collectors.toMap(KnowledgeField::getKnowledgeId, KnowledgeField::getProperty));

        Map<String, String> releaseSourceMap = releaseFieldList.stream().filter(item -> Const.DRUG_INFO_LIB_SOURCE_ID.equals(item.getKnowledgeLibFieldId()))
                .collect(Collectors.toMap(KnowledgeField::getKnowledgeId, KnowledgeField::getProperty));

        items.forEach(taskItem -> {
            taskItem.setDrugInfoLibCompany(taskItem.getStatus() == TaskItem.STATUS_RELEASED.intValue() ?
                    releaseCompanyMap.get(taskItem.getKnowledgeId()) : tempCompanyMap.get(taskItem.getKnowledgeId()));
            taskItem.setDrugInfoLibSource(taskItem.getStatus() == TaskItem.STATUS_RELEASED.intValue() ?
                    releaseSourceMap.get(taskItem.getKnowledgeId()) : tempSourceMap.get(taskItem.getKnowledgeId()));
        });
    }

    @ApiOperation(value = "uploadTaskFile", notes = "子任务上传附件接口")
    @PostMapping("uploadTaskFile")
    public TaskFile uploadTaskFile(MultipartFile file, String taskId) {
        String path = ApplicationContextUtil.BASE_DOWN_FORDER + "file/task/" + StringUtils.defaultIfEmpty(taskId, "temp") + "/";
        String fileName = UploadFileUtil.uploadFile(file, path, false);
        TaskFile taskFile = new TaskFile();
        taskFile.setTaskId(taskId);
        taskFile.setName(fileName);
        taskFile.setSize(UploadFileUtil.readableFileSize(new File(path + taskFile.getName()).length()));
        taskFile.setPath("file/task/" + StringUtils.defaultIfEmpty(taskId, "temp") + "/" + taskFile.getName());
        taskFileService.save(taskFile);
        return taskFile;
    }

    @ApiOperation(value = "removeTempFile", notes = "移除子任务上传附件接口")
    @GetMapping("removeTempFile")
    public void removeTempFile(String name) {
        File file = new File(ApplicationContextUtil.BASE_DOWN_FORDER + "file/task/temp/" + name);
        if (file.exists()) {
            if (file.delete()) {
            } else {
                throw new RuntimeException("未能删除附件" + name);
            }
        }
    }

    /**
     * 导出任务批量上传模板
     *
     * @throws UnsupportedEncodingException 如果在对文件名编码的过程出现异常
     * @throws IOException                  如果写入输出流的时候出现异常
     */
    @ApiOperation(value = "downLoadSubTaskTemplate", notes = "导出任务批量上传模板接口")
    @GetMapping("downLoadSubTaskTemplate")
    public void downLoadSubTaskTemplate(HttpServletResponse response) throws IOException {
        XSSFWorkbook workbook = getWorkbook();
        response.setContentType("application/xlsx;charset=UTF-8");
        response.addHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode("知识管理平台子任务批量上传模板.xlsx", "UTF-8"));
        workbook.write(response.getOutputStream());
        response.getOutputStream().close();
    }

    @NotNull
    private XSSFWorkbook getWorkbook() {
        XSSFWorkbook workbook = new XSSFWorkbook();
        XSSFSheet sheet = workbook.createSheet();

        XSSFRow row0 = sheet.createRow(0);
        XSSFCell cell00 = row0.createCell(0);
        cell00.setCellValue("子任务名称");
        XSSFCell cell01 = row0.createCell(1);
        cell01.setCellValue("备注");

        XSSFRow row1 = sheet.createRow(1);
        XSSFCell cell10 = row1.createCell(0);
        cell10.setCellValue("糖尿病");
        XSSFCell cell11 = row1.createCell(1);
        cell11.setCellValue("内分泌");

        XSSFRow row2 = sheet.createRow(2);
        XSSFCell cell20 = row2.createCell(0);
        cell20.setCellValue("高血压");
        XSSFCell cell21 = row2.createCell(1);
        cell21.setCellValue("心血管内科");

        XSSFRow row3 = sheet.createRow(3);
        XSSFCell cell30 = row3.createCell(0);
        cell30.setCellValue("说明：正式上传时请清楚示例数据和说明");
        return workbook;
    }

    @ApiOperation(value = "parseSubTaskTemplate", notes = "导入子任务模板接口")
    @PostMapping("parseSubTaskTemplate")
    public List<TaskItem> parseSubTaskTemplate(MultipartFile file) throws Exception {
        XSSFWorkbook workbook = getSubTaskTemplateWorkbook(file);
        XSSFSheet sheet = workbook.getSheetAt(0);
        sheet.getLastRowNum();
        if (sheet.getLastRowNum() > MAX_ROW_NUM) {
            throw new RuntimeException("单次导入的数据不能超过1000条");
        }
        List<TaskItem> taskItemList = buildSubTaskList(workbook);
        return taskItemList;
    }

    @NotNull
    private List<TaskItem> buildSubTaskList(XSSFWorkbook workbook) {
        List<TaskItem> list = new ArrayList<>();
        for (int i = 0; i < workbook.getNumberOfSheets(); i++) {
            XSSFSheet sheet = workbook.getSheetAt(i);
            for (int j = 1; j <= sheet.getLastRowNum(); j++) {
                XSSFRow row = sheet.getRow(j);
                XSSFCell cell0 = row.getCell(0);
                if (StringUtils.isBlank(cell0.getStringCellValue())) {
                    break;
                }
                XSSFCell cell1 = row.getCell(1);
                TaskItem taskItem = new TaskItem();
                taskItem.setName(ExcelUtil.superOrSubScript2007(cell0, workbook));
                if (cell1 == null) {
                    taskItem.setRemark("");
                } else {
                    CellType cellType = cell1.getCellTypeEnum();
                    if (cellType == CellType.NUMERIC) {
                        taskItem.setRemark(String.valueOf(cell1.getNumericCellValue()));
                    } else if (cellType == CellType.STRING) {
                        taskItem.setRemark(cell1.getStringCellValue());
                    }
                }
                taskItem.setRemark(cell1 == null ? "" : cell1.getStringCellValue());
                list.add(taskItem);
            }
        }
        return list;
    }

    private XSSFWorkbook getSubTaskTemplateWorkbook(MultipartFile multipartFile) throws Exception {
        String path = ApplicationContextUtil.BASE_DOWN_FORDER + "task/temp/";
        String fileName = UploadFileUtil.uploadFile(multipartFile, path, false);
        File file = new File(path + fileName);
        FileInputStream inputStream = new FileInputStream(file);
        XSSFWorkbook workbook = new XSSFWorkbook(inputStream);
        return workbook;
    }

    @ApiOperation(value = "selectTaskById", notes = "任务编辑根据任务id查询子任务")
    @GetMapping("selectTaskById")
    public Task selectTaskById(String taskId) {
        Task task = taskService.getById(taskId);
        task.setTaskItemList(taskItemService.getBaseMapper().selectBeansByWherePart("task_id = '" + taskId + "' order by updated_time desc"));
        task.setTaskFileList(taskFileService.getBaseMapper().selectBeansByWherePart("task_id = '" + taskId + "'"));
        return task;
    }

    @ApiOperation(value = "updateTaskById", notes = "任务编辑修改任务")
    @PostMapping("updateTaskById")
    public List<TaskItem> updateTaskById(@RequestBody Task task) {
        if (task.getAuditLevel() == Task.AUDIT_LEVEL_TWO) {
            taskItemService.update(Wrappers.lambdaUpdate(TaskItem.class).set(TaskItem::getStatus, TaskItem.STATUS_PASS_1).eq(TaskItem::getTaskId, task.getId()).eq(TaskItem::getStatus, TaskItem.STATUS_PASS));
        }
        if (task.getAuditLevel() == Task.AUDIT_LEVEL_THREE) {
            taskItemService.update(Wrappers.lambdaUpdate(TaskItem.class).set(TaskItem::getStatus, TaskItem.STATUS_PASS_2).eq(TaskItem::getTaskId, task.getId()).eq(TaskItem::getStatus, TaskItem.STATUS_PASS));
        }
        taskService.saveOrUpdate(task);
        List<TaskItem> list = taskItemService.lambdaQuery().eq(TaskItem::getTaskId, task.getId()).list();
        return list;
    }

    @ApiOperation(value = "selectSimilarTaskItem", notes = "子任务列表修改子任务接口")
    @GetMapping("selectSimilarTaskItem")
    public List<TaskItem> selectSimilarTaskItem(String taskItemName, String knowledgeLibId) {

        List<TaskItem> similarTaskItemList = taskService.selectSimilarTaskItem(taskItemName, knowledgeLibId);
        return similarTaskItemList;
    }

    @ApiOperation(value = "selectSimilarTaskItemList", notes = "对比现有子任务接口")
    @PostMapping("selectSimilarTaskItemList")
    public List<TaskItem> selectSimilarTaskItemList(String taskItemList, String knowledgeLibId) {
        List<TaskItem> taskItemLists = JSON.parseArray(taskItemList, TaskItem.class);
        for (TaskItem taskItem : taskItemLists) {
            List<TaskItem> similarTaskItemList = taskService.selectSimilarTaskItem(taskItem.getName(), knowledgeLibId);
            taskItem.setSimilarTaskItemList(similarTaskItemList);
        }
        return taskItemLists;
    }

    /**
     * 保存taskItem, 如果是修订, 则校验temp表是否有数据;
     */
    @ApiOperation(value = "saveTaskItem", notes = "保存taskItem, 如果是修订, 则校验temp表是否有数据;")
    @PostMapping("saveTaskItem")
    public TaskItem saveTaskItem(String taskItem) {
        TaskItem item = JSON.parseObject(taskItem, TaskItem.class);
        taskService.saveTaskItem(item, PMPHAppUtil.getCurrentUserEnName());
        return item;
    }

    @ApiOperation(value = "taskItemSave", notes = "活动详情保存子任务接口")
    @PostMapping("taskItemSave")
    public void taskItemSave(String taskItem, String activityItem) {
        TaskItem taskItems = JSON.parseObject(taskItem, TaskItem.class);
        ActivityItem activityItems = JSON.parseObject(activityItem, ActivityItem.class);
        taskService.taskItemAdd(taskItems, PMPHAppUtil.getCurrentUserEnName(), activityItems);
    }

    @ApiOperation(value = "addTaskItem", notes = "保存子任务接口")
    @PostMapping("addTaskItem")
    public void addTaskItem(String taskId, String taskItemList) {
        List<TaskItem> taskItems = JSON.parseArray(taskItemList, TaskItem.class);
        for (TaskItem taskItem : taskItems) {
            taskItem.setTaskId(taskId);
            taskService.saveTaskItem(taskItem, PMPHAppUtil.getCurrentUserEnName());
        }
    }

    @ApiOperation(value = "updateTaskItemList", notes = "子任务分配接口")
    @PostMapping("updateTaskItemList")
    public void updateTaskItemList(@RequestBody List<TaskItem> taskItemList) {
        taskItemService.saveOrUpdateBatch(taskItemList);
    }

    @ApiOperation(value = "deleteTaskFileById", notes = "删除子任务附件接口")
    @PostMapping("deleteTaskFileById")
    public void deleteTaskFileById(String taskFile) {
        TaskFile taskFiles = JSON.parseObject(taskFile, TaskFile.class);
        boolean deleteSuccessfully = taskService.deleteTaskFile(taskFiles);
        if (deleteSuccessfully) {
        } else {
            throw new RuntimeException("文件" + taskFiles.getPath() + "删除失败");
        }
    }

    @ApiOperation(value = "deleteTaskItemById", notes = "子任务列表删除接口")
    @PostMapping("deleteTaskItemById")
    public void deleteTaskItemById(String taskItem) {
        TaskItem item = JSON.parseObject(taskItem, TaskItem.class);
        taskService.deleteTaskItem(item);
    }

    @ApiOperation(value = "selectSystemOptions", notes = "查询tabs")
    @GetMapping("selectSystemOptions")
    public List<Map<String, String>> selectSystemOptions() {
        List<Map<String, String>> list = new ArrayList<>();
        Map<String, String> map1 = new HashMap<>(16);
        map1.put("label", "标准知识库");
        map1.put("value", "knowledge");
        list.add(map1);
        Map<String, String> map2 = new HashMap<>(16);
        map2.put("label", "医学计算器");
        map2.put("value", "calc");
        list.add(map2);
        Map<String, String> map3 = new HashMap<>(16);
        map3.put("label", "流程图");
        map3.put("value", "flowchart");
        list.add(map3);
        return list;
    }

    /**
     * 根据任务ID启动指定的任务.
     *
     * @throws Exception 如果任务ID为空.
     */
    @ApiOperation(value = "start", notes = "根据任务ID启动指定的任务.")
    @GetMapping("start")
    public void start(String id) throws Exception {
        if (id == null) {
            throw new Exception("任务ID为空！");
        }
        String result = taskService.start(id);
        if (result.equals(TaskService.UPDATE_SUCCESS)) {
        } else {
            throw new RuntimeException("启动任务失败！");
        }
    }

    /**
     * 根据任务ID逻辑删除指定任务.
     *
     * @throws Exception 如果任务ID为空.
     */
    @ApiOperation(value = "delete", notes = "根据任务ID逻辑删除指定任务.")
    @GetMapping("delete")
    public void delete(String id) throws Exception {
        if (id == null) {
            throw new Exception("任务ID为空！");
        }
        String result = taskService.delete(id);
        if (result.equals(TaskService.UPDATE_SUCCESS)) {
        } else {
            throw new RuntimeException("删除任务失败！");

        }
    }

    /**
     * 根据任务ID完成指定任务.
     *
     * @throws Exception 如果任务ID为空.
     */
    @ApiOperation(value = "finish", notes = "根据任务ID完成指定任务")
    @GetMapping("finish")
    public void finish(@Nonnull String id) {
        taskService.finish(id);
    }

    @ApiOperation(value = "batchSubmit", notes = "批量提交接口")
    @GetMapping("batchSubmit")
    public void batchSubmit(String taskId, String name) {
        try {
            taskService.batchSubmit(taskId, name);
        } catch (Exception e) {
            log.error("我的编辑列表，批量提交失败", e);
        }
    }

    /**
     * 提交任务数据
     *
     * @throws Exception 如果参数为空
     */
    @ApiOperation(value = "submit", notes = "提交任务数据接口")
    @PostMapping("submit")
    public void submit(String task) throws Exception {

        if (StringUtils.isBlank(task)) {
            throw new Exception("参数task为空");
        }
        taskService.saveTask(task);
    }

    /**
     * 根据知识id, 查询正在进行中的子任务
     */
    @ApiOperation(value = "selectTaskItemInProcessByKnowledgeId", notes = "根据知识id, 查询正在进行中的子任务")
    @GetMapping("selectTaskItemInProcessByKnowledgeId")
    public List<TaskItem> selectTaskItemInProcessByKnowledgeId(String knowledgeId) {
        // 查询正在进行中的子任务, 是否有当前知识;
        List<TaskItem> taskItems = taskItemService.getBaseMapper().selectBeansByWherePart(
                "knowledge_id = '" + knowledgeId + "' " +
                        " and status != " + TaskItem.STATUS_RELEASED + " and deleted = 0");
        return taskItems;
    }

    /**
     * 根据知识id, 查询是否有正在编辑的子任务;
     */
    @ApiOperation(value = "selectKnowledgeInProcessFlag", notes = "根据知识id, 查询是否有正在编辑的子任务")
    @GetMapping("selectKnowledgeInProcessFlag")
    public boolean selectKnowledgeInProcessFlag(@Nonnull String knowledgeId) {
        return taskItemService.lambdaQuery()
                .eq(TaskItem::getKnowledgeId, knowledgeId)
                .eq(TaskItem::getDeleted, TaskItem.NO_DELETED)
                .ne(TaskItem::getStatus, TaskItem.STATUS_RELEASED)
                .list().size() > 0;
    }

    /**
     * 根据知识id, 查询最近一次已完成子任务;
     */
    @ApiOperation(value = "selectLastFinishedTaskItemByKnowledgeId", notes = "根据知识id, 查询最近一次已完成子任务")
    @GetMapping("selectLastFinishedTaskItemByKnowledgeId")
    public TaskItem selectLastFinishedTaskItemByKnowledgeId(@Nonnull String knowledgeId) {
        return taskItemService.getLastFinishedTaskItemByKnowledgeId(knowledgeId);
    }

    /**
     * 根据知识库id, 查询正在进行中的子任务, 只能查询当前用户创建的知识;
     */
    @ApiOperation(value = "selectTaskInProcessByKnowledgeLibId", notes = "根据知识库id, 查询正在进行中的子任务, 只能查询当前用户创建的知识")
    @GetMapping("selectTaskInProcessByKnowledgeLibId")
    public List<Task> selectTaskInProcessByKnowledgeLibId(String knowledgeLibId) {
        // 查询正在进行中的子任务, 是否有当前知识;
        List<Task> tasks = taskService.getBaseMapper().selectBeansByWherePart(
                " knowledge_lib_id = '" + knowledgeLibId + "' and deleted = 0 and status != " + Task.STATUS_FINISHED);
        return tasks;
    }

    @ApiOperation(value = "selectAuditTaskList", notes = "我的知识审核页面左侧任务列表")
    @GetMapping("selectAuditTaskList")
    public Map<String, Object> selectAuditTaskList(String systemType) {
        String username = PMPHAppUtil.getCurrentUserEnName();
        // 获取任务id, 根据子任务更新时间排序;
        List<String> taskIdList = taskItemService.list(
                new QueryWrapper<TaskItem>().lambda().select(TaskItem::getTaskId)
                        .ne(TaskItem::getStatus, TaskItem.STATUS_NOT_COMMIT)
                        .ne(TaskItem::getStatus, TaskItem.STATUS_REJECT)
                        // 初审, 复审, 终审为当前用户;
                        .and(qr -> qr.eq(TaskItem::getFirstAuditor, username)
                                .or().eq(TaskItem::getSecondAuditor, username)
                                .or().eq(TaskItem::getThirdAuditor, username))
                        .orderByDesc(TaskItem::getUpdatedTime).orderByAsc(TaskItem::getId))
                .stream().map(TaskItem::getTaskId).distinct().collect(Collectors.toList());
        // 避免taskIdList为空导致后面报错
        taskIdList.add("");
        // 获取当前用户下任务;
        Map<String, Task> taskMap = taskService.lambdaQuery()
                .eq(StringUtils.isNotEmpty(systemType), Task::getSystemType, systemType)
                .eq(Task::getStatus, Task.STATUS_STARTED)
                .eq(Task::getDeleted, Task.NOT_DELETED)
                .in(Task::getId, taskIdList).list().stream().collect(Collectors.toMap(Task::getId, Function.identity()));
        List<Task> result = taskIdList.stream()
                .map(taskMap::get)
                .filter(Objects::nonNull)
                .collect(Collectors.toList());
        // 获取当前用户下已完成任务;
        Map<String, Task> completeTaskMap = taskService.lambdaQuery()
                .eq(StringUtils.isNotEmpty(systemType), Task::getSystemType, systemType)
                .eq(Task::getStatus, Task.STATUS_FINISHED)
                .eq(Task::getDeleted, Task.NOT_DELETED)
                .in(Task::getId, taskIdList).list().stream().collect(Collectors.toMap(Task::getId, Function.identity()));
        List<Task> completeResult = taskIdList.stream()
                .map(completeTaskMap::get)
                .filter(Objects::nonNull)
                .collect(Collectors.toList());

        if (CollectionUtils.isNotEmpty(result)) {
            // 当前用户, 待审核的子任务;
            List<TaskItem> taskItemList = taskItemService.lambdaQuery().eq(TaskItem::getCrtOperator, username)
                    .in(TaskItem::getStatus, TaskItem.STATUS_COMMIT, TaskItem.STATUS_PASS_1, TaskItem.STATUS_PASS_2)
                    .list();
            result.forEach(task -> {
                List<TaskItem> collect = taskItemList.stream().filter(taskItem -> task.getId().equals(taskItem.getTaskId())).collect(Collectors.toList());
                task.setTaskItemList(collect);
            });
        }
        Map<String, Object> map = new HashMap<>();
        map.put("result", result);
        map.put("completeResult", completeResult);
        return map;
    }

    @ApiOperation(value = "selectSubTaskList", notes = "查询右侧子任务列表接口")
    @GetMapping("selectSubTaskList")
    public Map<String, Object> selectSubTaskList(String system, String page, String size, String status, String lib,
                                                 String editor, String date, String taskId, String name, String drugInfoLibCompany) {

        String currentUser = PMPHAppUtil.getCurrentUserEnName();
        // 当前用户参与审核的子任务, 都展示;
        String sql = "select ti.*, t.knowledge_lib_id, t.audit_level, t.system_type, t.enable_create" +
                " from task_item ti " +
                "left join task t on ti.task_id = t.id " +
                "where ti.deleted = " + TaskItem.NO_DELETED +
                " and ti.status != 0 and ti.status != 3 " +
                " and (ti.first_auditor = '" + currentUser + "' " +
                " || ti.second_auditor = '" + currentUser + "' " +
                " || ti.third_auditor = '" + currentUser + "') ";
        if (StringUtils.isNotEmpty(system) && !"all".equals(system)) {
            sql += " and t.system_type = '" + system + "'";
        }
        if (StringUtils.isNotBlank(status)) {
            if ("auditing".equals(status)) {
                // 当前用户审核中的任务;
                sql += " and ti.crt_operator = '" + currentUser + "' and ti.status in (1, 4, 6) ";
            } else if ("reject".equals(status)) {
                // 当前用户被上级驳回的任务;
                sql += " and ti.crt_operator = '" + currentUser + "' and ti.status in (3, 5, 7, 9) ";
            } else if ("pass".equals(status)) {
                // 一审用户, 除去一审中和二审驳回的任务;
                sql += " and ( (ti.first_auditor = '" + currentUser + "' && ti.status not in(1, 5)) " +
                        // 二审用户, 三审中, 通过, 发布的任务;
                        " || (ti.second_auditor = '" + currentUser + "' && ti.status in (6, 2)) " +
                        // 三审用户, 通过的数据;
                        " || (ti.third_auditor = '" + currentUser + "' && ti.status = 2 ) ) ";
            } else if ("released".equals(status)) {
                sql += " and ti.status = " + TaskItem.STATUS_RELEASED;
            }
        }
        if (StringUtils.isNotBlank(lib)) {
            sql += " and t.knowledge_lib_id = '" + lib + "'";
        }
        if (StringUtils.isNotBlank(date)) {
            JSONArray jsonArray = JSONArray.parseArray(date);
            if (jsonArray.size() >= 2) {
                String start = jsonArray.getString(0);
                String end = jsonArray.getString(1);
                sql += " and (ti.submit_time >= '" + start + "' && ti.submit_time <= '" + end + "')";
            }
        }
        if (StringUtils.isNotBlank(taskId)) {
            sql += " and ti.task_id = '" + taskId + "'";
        }
        if (StringUtils.isNotBlank(name)) {
            sql += " and ti.name like '%" + name + "%'";
        }
        if (StringUtils.isNotBlank(editor)) {
            sql += " and ti.editor = '" + editor + "'";
        }
        if (StringUtils.isNotBlank(drugInfoLibCompany)) {
            sql += " and ti.knowledge_id in " +
                    " (select knowledge_id from temp_knowledge_field where knowledge_lib_field_id = '" + Const.DRUG_INFO_LIB_COMPANY_ID + "' and property like '%" + drugInfoLibCompany + "%' " +
                    " union all" +
                    " select knowledge_id from released_knowledge_field where knowledge_lib_field_id = '" + Const.DRUG_INFO_LIB_COMPANY_ID + "' and property like '%" + drugInfoLibCompany + "%' )";
        }
        sql += " order by ti.updated_time desc ";
        List<TaskItem> taskItemLists = taskItemService.getBaseMapper().executeMultiSelect(sql);
        int total = taskItemLists.size();

        if (StringUtils.isNotBlank(page) && StringUtils.isNotBlank(size)) {
            int pageNum = Integer.parseInt(page);
            int sizeNum = Integer.parseInt(size);
            sql += " limit " + (pageNum * sizeNum) + ", " + sizeNum;
        }
        List<TaskItem> taskItemList = taskItemService.getBaseMapper().executeMultiSelect(sql);
        queryDrug(taskItemList);
        Map<String, Object> resMap = new HashMap<>(16);
        resMap.put("subTasks", taskItemList);
        resMap.put("total", total);
        return resMap;
    }

    @ApiOperation(value = "selectTask4TaskDetail", notes = "子任务详情接口")
    @GetMapping("selectTask4TaskDetail")
    public Map<String, Object> selectTask4TaskDetail(String id, String size, String page) {
        int subTaskListSize = Integer.parseInt(size);
        int subTaskListPage = Integer.parseInt(page);
        assert Objects.nonNull(id) : "task id is null";

        AtomicReference<Task> taskAtomicReference = new AtomicReference<>();
        AtomicReference<String> libNameAtomicReference = new AtomicReference<>();
        AtomicReference<List<TaskFile>> taskFileListAtomicReference = new AtomicReference<>();
        AtomicReference<List<TaskItem>> taskItemListAtomicReference = new AtomicReference<>();
        AtomicInteger totalNum = new AtomicInteger(0);

        CompletableFuture<Task> queryTask = CompletableFuture.supplyAsync(() -> {
            Task task = taskService.getById(id);
            taskAtomicReference.set(task);
            return task;
        });
        CompletableFuture<String> queryLibName = queryTask.thenApplyAsync(task -> {
            if (CALCULATOR_LIB_ID.equals(task.getKnowledgeLibId())) {
                return "医学计算器";
            } else if (FLOW_CHART_LIB_ID.equals(task.getKnowledgeLibId())) {
                return "流程图";
            }
            KnowledgeLib lib = knowledgeLibService.getById(task.getKnowledgeLibId());
            libNameAtomicReference.set(lib.getName());
            return lib.getName();
        });
        CompletableFuture<Void> buildAttachmentList = queryTask.thenAcceptAsync(task -> {
            String sql = "select * from task_file where task_id = '" + task.getId() + "'";
            List<TaskFile> taskFiles = taskFileService.getBaseMapper().executeMultiSelect(sql);
            taskFileListAtomicReference.set(taskFiles);
        });
        CompletableFuture<Void> queryTaskItems = queryTask.thenAcceptAsync(task -> {
            String sql = "select * from task_item where task_id = '" + task.getId() + "' limit " + (subTaskListPage * subTaskListSize) + ", " + subTaskListSize;
            List<TaskItem> taskItems = taskItemService.getBaseMapper().executeMultiSelect(sql);
            taskItemListAtomicReference.set(taskItems);
            String sql4Count = "select *  from task_item where task_id = '" + task.getId() + "'";
            List<TaskItem> taskItemList = taskItemService.getBaseMapper().executeMultiSelect(sql4Count);
            totalNum.set(taskItemList.size());
        });
        CompletableFuture<Void> allCompleted = CompletableFuture.allOf(queryLibName, buildAttachmentList, queryTaskItems);
        allCompleted.join();

        Map<String, Object> responseMap = new HashMap<>(16);
        responseMap.put("basicInfo", getBasicInfo(taskAtomicReference.get(), libNameAtomicReference.get(), taskFileListAtomicReference.get()));
        responseMap.put("subTask", taskItemListAtomicReference.get());
        responseMap.put("subTaskTotal", totalNum.get());
        return responseMap;
    }

    @ApiOperation(value = "press", notes = "子任务催办接口")
    @GetMapping("press")
    public void press(String id, String type) {
        String sql = "";
        if (StringUtils.equals(type, "all")) {
            sql = "update task_item set press = 1,updated_time = '" + LocalDateTimeUtil.getNowAsString() + "' where task_id = '" + id + "' and status != " + TaskItem.STATUS_RELEASED;
        } else {
            sql = "update task_item set press = 1,updated_time = '" + LocalDateTimeUtil.getNowAsString() + "' where id = '" + id + "' and status != " + TaskItem.STATUS_RELEASED;
        }
        taskItemService.getBaseMapper().executeDelete(sql);
    }

    private Object getBasicInfo(Task task, String libName, List<TaskFile> taskFileList) {
        Map<String, Object> basicInfoMap = new HashMap<>(16);
        basicInfoMap.put("id", task.getId());
        basicInfoMap.put("name", task.getName());
        basicInfoMap.put("selfAdd", task.getEnableCreate() == 1);
        basicInfoMap.put("system", task.getSystemType());
        basicInfoMap.put("libName", libName);
        List<String> dateRangeList = new ArrayList<>();
        dateRangeList.add(task.getStartDate());
        dateRangeList.add(task.getEndDate());
        basicInfoMap.put("dateRange", dateRangeList);
        basicInfoMap.put("reviewLevel", task.getAuditLevel());
        basicInfoMap.put("fileList", taskFileList);
        basicInfoMap.put("comment", task.getRemark());
        return basicInfoMap;
    }

    @ApiOperation(value = "cancelAudit", notes = "子任务状态退回到最后一步审核状态")
    @GetMapping("cancelAudit")
    public void cancelAudit(String id, String reason) {
        List<TaskItem> taskItems = taskItemService.getBaseMapper().selectBeansByWherePart(
                "knowledge_id = '" + id + "' and status = " + TaskItem.STATUS_PASS);
        String result;
        if (taskItems.size() == 1) {
            result = taskService.cancelAudit(taskItems.get(0).getId(), taskItems.get(0).getKnowledgeId(), reason);
        } else if (taskItems.size() > 1) {
            log.error("知识（" + id + "）绑定了多条子任务");
            result = "知识（" + id + "）绑定了多条子任务";
        } else {
            result = "知识（" + id + "）没有绑定子任务";
        }

        if (TaskService.UPDATE_SUCCESS.equals(result)) {
        } else {
            throw new RuntimeException(result);
        }
    }

    @ApiOperation(value = "selectNoCommitKnowledge", notes = "搜索当前条件下待提交的数据")
    @GetMapping("selectNoCommitKnowledge")
    public List<TaskItem> selectNoCommitKnowledge(String taskId, String name) {
        String sql = "select id from task_item where task_id = '" + taskId + "' and knowledge_id is not null " +
                " and knowledge_id != '' and editor = '" + PMPHAppUtil.getCurrentUserEnName() + "' and status =" + TaskItem.STATUS_NOT_COMMIT + " and deleted =  " + TaskItem.NO_DELETED;
        if (StringUtils.isNotBlank(name)) {
            sql += " and name like '%" + name + "%'";
        }
        List<TaskItem> list = taskItemService.getBaseMapper().executeMultiSelect(sql);
        return list;
    }

    @ApiOperation(value = "delById", notes = "根据子任务id删除子任务")
    @GetMapping("delById")
    public void delById(String id, String knowledgeId, String systemType) {
        TaskItem taskItem = new TaskItem();
        taskItem.setId(id);
        taskItem.setKnowledgeId(knowledgeId);
        taskItem.setSystemType(systemType);
        try {
            taskService.deleteTaskItem(taskItem);
        } catch (Exception e) {
            log.error("从我的编辑任务列表删除失败:", e);
            throw new RuntimeException("删除失败");
        }
    }

    @ApiOperation(value = "selectTaskItem", notes = "根据子任务id获取子任务")
    @GetMapping("selectTaskItem")
    public List<TaskItem> selectTaskItem(String taskId) {
        List<TaskItem> taskItems = taskItemService.getBaseMapper().selectBeansByWherePart(" task_id='" + taskId + "' order by updated_time desc");
        return taskItems;
    }

    @ApiOperation(value = "selectDetailTableData", notes = "查询详情数据")
    @GetMapping("selectDetailTableData")
    public Map<String, Object> selectDetailTableData(String taskId, String status, String name, String editor,
                                                     String firstAuditor, String secondAuditor, String thirdAuditor,
                                                     Integer currentPage, Integer pageNum) {
        Page<TaskItem> taskItemPage = taskItemService.lambdaQuery()
                .eq(StringUtils.isNotBlank(taskId), TaskItem::getTaskId, taskId)
                .like(StringUtils.isNotBlank(name), TaskItem::getName, name)
                .eq(StringUtils.isNotBlank(editor), TaskItem::getEditor, editor)
                .eq(StringUtils.isNotBlank(firstAuditor), TaskItem::getFirstAuditor, firstAuditor)
                .eq(StringUtils.isNotBlank(secondAuditor), TaskItem::getSecondAuditor, secondAuditor)
                .eq(StringUtils.isNotBlank(thirdAuditor), TaskItem::getThirdAuditor, thirdAuditor)
                .eq(StringUtils.isNotBlank(status), TaskItem::getStatus, status)
                .page(new Page<>(currentPage, pageNum));


        Map<String, Object> map = new HashMap<>(16);
        map.put("tableData", taskItemPage.getRecords());
        map.put("totalNum", taskItemPage.getTotal());
        return map;
    }

    @ApiOperation(value = "selectQuestionAnswerTaskId", notes = "查询问答库任务")
    @GetMapping("selectQuestionAnswerTaskId")
    public List<Task> selectQuestionAnswerTaskId() {
        String knowledgeLibId = Const.QW_LIB_ID;
        // 查询正在进行中的子任务, 是否有当前知识;
        List<Task> tasks = taskService.lambdaQuery().eq(Task::getDeleted, Task.NOT_DELETED).eq(Task::getKnowledgeLibId, knowledgeLibId).eq(Task::getCreatedBy, PMPHAppUtil.getCurrentUserEnName()).list();
        return tasks;
    }

    @ApiOperation(value = "selectFinishTaskItemList", notes = "查询我的审核已完成的任务列表")
    @GetMapping("selectFinishTaskItemList")
    public Map<String, Object> selectFinishTaskItemList(String drugInfoLibCompany, String taskId, String lib, String editor, String name,
                                                        String date, String page, String size) {
        TaskItem taskItem = new TaskItem();
        taskItem.setTaskId(taskId);
        taskItem.setKnowledgeLibId(lib);
        taskItem.setEditor(editor);
        taskItem.setName(name);
        JSONArray jsonArray = JSONArray.parseArray(date);
        if (jsonArray.size() >= 2) {
            taskItem.setStartDate(jsonArray.getString(0));
            taskItem.setEndDate(jsonArray.getString(1));
        }
        // 当前页数
        int currentPage = Integer.parseInt(page);
        // 每页显示数量
        int pageNum = Integer.parseInt(size);
        Page pages = new Page(currentPage, pageNum);
        IPage<TaskItem> taskItemIPage = taskItemService.getBaseMapper().selectAuditFinishTaskItem(pages, PMPHAppUtil.getCurrentUserEnName(), drugInfoLibCompany, taskItem);
        queryDrug(taskItemIPage.getRecords());
        Map<String, Object> resMap = new HashMap<>(16);
        resMap.put("subTasks", taskItemIPage.getRecords());
        resMap.put("total", taskItemIPage.getTotal());
        return resMap;
    }

    @ApiOperation(value = "selectFinishEditTaskList", notes = "查询我的编辑已完成的任务列表")
    @GetMapping("selectFinishEditTaskList")
    public Map<String, Object> selectFinishEditTaskList(String taskId, String status, String name, String taskType,
                                                        String drugInfoLibCompany, String page, String size) {

        int currentPage = Integer.parseInt(page);
        // 每页显示数量
        int pageNum = Integer.parseInt(size);
        Page pages = new Page(currentPage, pageNum);
        IPage<TaskItem> taskItemIPage = taskItemService.getBaseMapper().selectEditFinishTaskItem(pages, Const.DRUG_INFO_LIB_ID, Const.DRUG_INFO_LIB_COMPANY_ID, Const.DRUG_INFO_LIB_SOURCE_ID, PMPHAppUtil.getCurrentUserEnName(), taskId, name, taskType, drugInfoLibCompany, status);
        KnowledgeLib knowledgeLibs = null;
        if (CollectionUtils.isNotEmpty(taskItemIPage.getRecords())) {
            if (!"calculator_lib_id".equals(taskItemIPage.getRecords().get(0).getKnowledgeLibId()) || !"flow_chart_lib_id".equals(taskItemIPage.getRecords().get(0).getKnowledgeLibId()) || StringUtils.isNotBlank(taskItemIPage.getRecords().get(0).getKnowledgeLibId())) {
                knowledgeLibs = knowledgeLibService.getById(taskItemIPage.getRecords().get(0).getKnowledgeLibId());
            }
        }
        queryDrug(taskItemIPage.getRecords());
        for (TaskItem item : taskItemIPage.getRecords()) {
            if ("knowledge".equals(item.getSystemType())) {
                if (knowledgeLibs != null) {
                    item.setKnowledgeLibName(knowledgeLibs.getName());
                } else {
                    item.setKnowledgeLibName("");
                }
            }
        }
        Map<String, Object> resMap = new HashMap<>(16);
        resMap.put("tableData", taskItemIPage.getRecords());
        resMap.put("totalNum", taskItemIPage.getTotal());
        return resMap;
    }
}
